package com.example.yls.demoa;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

public class MainActivity extends AppCompatActivity {
    private Button btnGet;
    private ImageView ivResult;
    private RequestQueue requestQueue;
    private ImageLoader imageLoader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        requestQueue = Volley.newRequestQueue(MainActivity.this);
        imageLoader = new ImageLoader(requestQueue,new BitmapImageCache());
        btnGet = findViewById(R.id.btn_get);
        ivResult = findViewById(R.id.iv_result);
        btnGet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getImageUseImageLoder();
            }
        });
    }

    private void getImageUseImageLoder() {


        ImageLoader.ImageListener imageListener = ImageLoader.getImageListener(ivResult,R.drawable.
                lighthouse,R.drawable.penguins);
        String imgUrl = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3015542620,2503136042&fm=27&gp=0.jpg";
        imageLoader.get(imgUrl,imageListener);

    }
}
